import { NImage, NSwitch } from "naive-ui";
import { h } from "vue";
import { formatToDateTime } from '@/utils/dateUtil'

export const createListColumns = ({ currentIndex, switchStatus }) => {
  return [
    {
      title: '序号',
      key: 'index',
      align: 'center',
      width: 60,
      render: (...[, record]) => {
        return currentIndex() + record + 1;
      },
    },
    {
      title: '医院图标',
      key: 'logoData',
      render(row) {
        return h(NImage, {
          src: `data:image/jpeg;base64,${row.logoData}`,
          width: '50',
          color: '#fff'
        });
      }
    },
    {
      title: '医院名称',
      key: 'hosname',
    },
    {
      title: '医院等级',
      width: 100,
      key: 'param.hostypeName',
    },
    {
      title: '详细地址',
      key: 'param.fullAddress',
    },
    {
      title: '状态',
      key: 'status',
      width: 80,
      render(row) {
        return h(NSwitch, {
          value: row.status === 1 ? true : false,
          onClick: () => switchStatus(row),
        });
      },
    },
    {
      title: '创建时间',
      key: 'createTime',
      render(row) {
        return formatToDateTime(row.createTime)
      }
    },
  ]
}

export const createSchemas = (hosTypeOptions, provinceOptions, cityOptions, {fetchTypeOptions, fetchProvinceOptions, fetchCityOptions}) => {
  return [
    {
      field: 'hosname',
      component: 'NInput',
      label: '医院名称',
      defaultValue: '',
      labelMessge: '筛选医院名称',
      componentProps: {
        placeholder: '请输入医院名称',
      }
    },
    {
      field: 'hoscode',
      component: 'NInput',
      label: '医院编号',
      defaultValue: '',
      labelMessge: '筛选医院编号',
      componentProps: {
        placeholder: '请输入医院编号',
      }
    },
    {
      field: 'hostype',
      component: 'NSelect',
      label: '医院类型',
      labelMessge: '筛选医院类型',
      componentProps: {
        placeholder: '请选择医院类型',
        onUpdateShow: fetchTypeOptions,
        options: hosTypeOptions
      }
    },
    {
      field: 'provinceCode',
      component: 'NSelect',
      label: '筛选省',
      labelMessge: '筛选省',
      componentProps: {
        placeholder: '请选择省',
        onUpdateShow: fetchProvinceOptions,
        options: provinceOptions
      }
    },
    {
      field: 'cityCode',
      component: 'NSelect',
      label: '筛选市',
      labelMessge: '筛选市',
      componentProps: {
        placeholder: '请选择市',
        onUpdateShow: fetchCityOptions,
        options: cityOptions
      }
    },
  ];
}

export function createActions(record, {handleCat, handleSchedule }) {
  return [
    {
      label: '查看',
      type: 'primary',
      onClick: handleCat.bind(null, record)
    },
    {
      label: '排班',
      type: 'primary',
      onClick: handleSchedule.bind(null, record)
    }
  ];
}

export const scheduleTableColumn = [
  {
    title: '序号',
    width: 60,
    align: 'center',
    render: (text, record, index) => {
      return record + 1
    }
  },
  {
    title: '职称',
    key: 'title',
    render: (row) => {
      return `${row.title}|${row.docname}`
    }
  },
  {
    title: '号源时间',
    key: 'workTime',
    render: (row) => {
      return row.workTime == 0 ? '上午' : '下午'
    }
  },
  {
    title: '可预约数',
    key: 'reservedNumber'
  },
  {
    title: '剩余预约数',
    key: 'availableNumber'
  },
  {
    title: '挂号费(元)',
    key: 'amount'
  },
  {
    title: '擅长技能',
    key: 'skill'
  }
]